<template>
  <MkDialogEdit ref='dialogRef' v-model:isEdit='ctx.isEdit' @submit='submit'>
    <MkForm :model='ctx.mingXi' ref='formMingXiRef' formId='InvRuKuMingXi'>
      <MkSelectBasEntity label='血液品种' v-model='ctx.mingXi.xueYePinZhong' prop='xueYePinZhong' required :isEdit='false'
        entity="BasXueYePinZhong" />
      <MkSelectEnum label='Rh(D)' v-model='ctx.mingXi.rhD' prop='rhD' required :isEdit='false' enumType="RhDYueXue" />
      <MkInputNumber label='A型容量' v-model='ctx.mingXi.rongLiangA' prop='rongLiangA' :isEdit='ctx.isEdit'>
        <template #suffix>
          <span>{{ ctx.mingXi.danWei }}</span>
        </template>
      </MkInputNumber>
      <MkInputNumber label='B型容量' v-model='ctx.mingXi.rongLiangB' prop='rongLiangB' :isEdit='ctx.isEdit'>
        <template #suffix>
          <span>{{ ctx.mingXi.danWei }}</span>
        </template>
      </MkInputNumber>
      <MkInputNumber label='O型容量' v-model='ctx.mingXi.rongLiangO' prop='rongLiangO' :isEdit='ctx.isEdit'>
        <template #suffix>
          <span>{{ ctx.mingXi.danWei }}</span>
        </template>
      </MkInputNumber>
      <MkInputNumber label='AB型容量' v-model='ctx.mingXi.rongLiangAB' prop='rongLiangAB' :isEdit='ctx.isEdit'>
        <template #suffix>
          <span>{{ ctx.mingXi.danWei }}</span>
        </template>
      </MkInputNumber>
    </MkForm>
  </MkDialogEdit>

</template>

<script lang='ts' setup>
import { InvYueXueApi, InvYueXueMingXi, InvYueXueOutput } from '/@/api/inv/InvYueXue';
import { isNull } from '/@/utils';
const emits = defineEmits(['updateMingXi'])

const ctx = reactive({
  isEdit: false,
  isAdd: false,
  mingXi: {} as InvYueXueMingXi,
});

const dialogRef = ref();
const formRef = ref();

/** 打开弹框 */
const open = async (row: InvYueXueMingXi) => {
  dialogRef.value.show();

  ctx.isAdd = false;
  ctx.isEdit = false;
  ctx.mingXi = JSON.parse(JSON.stringify(row));
};

const close = () => {
  dialogRef.value?.close();
};

const submit = async () => {
  if (!ctx.isEdit) {
    close();
    return;
  }
  if (!isNull(ctx.mingXi.id)) {

  }
  emits('updateMingXi', ctx.mingXi)
  close();
};

defineExpose({ open })
</script>